
/**       
 * 对Date的扩展，将 Date 转化为指定格式的String       
 * 月(M)、日(d)、12小时(h)、24小时(H)、分(m)、秒(s)、周(E)、季度(q) 可以用 1-2 个占位符       
 * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)       
 * eg:       
 * (new Date()).pattern("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423       
 * (new Date()).pattern("yyyy-MM-dd E HH:mm:ss") ==> 2009-03-10 二 20:09:04       
 * (new Date()).pattern("yyyy-MM-dd EE hh:mm:ss") ==> 2009-03-10 周二 08:09:04       
 * (new Date()).pattern("yyyy-MM-dd EEE hh:mm:ss") ==> 2009-03-10 星期二 08:09:04       
 * (new Date()).pattern("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18       
 */          
Date.prototype.pattern=function(fmt) {           
    var o = {           
    "M+" : this.getMonth()+1, //月份           
    "d+" : this.getDate(), //日           
    "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, //小时           
    "H+" : this.getHours(), //小时           
    "m+" : this.getMinutes(), //分           
    "s+" : this.getSeconds(), //秒           
    "q+" : Math.floor((this.getMonth()+3)/3), //季度           
    "S" : this.getMilliseconds() //毫秒           
    };           
    var week = {           
    "0" : "/u65e5",           
    "1" : "/u4e00",           
    "2" : "/u4e8c",           
    "3" : "/u4e09",           
    "4" : "/u56db",           
    "5" : "/u4e94",           
    "6" : "/u516d"          
    };           
    if(/(y+)/.test(fmt)){           
        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));           
    }           
    if(/(E+)/.test(fmt)){           
        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);           
    }           
    for(var k in o){           
        if(new RegExp("("+ k +")").test(fmt)){           
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));           
        }           
    }           
    return fmt;           
};  



//ui 时间控件判断js
function timetime(){
  var startDate = new Date();
  var endDate = new Date();

  $('#my-startDate').val((new Date()).pattern("yyyy-MM-dd"));
  $('#my-endDate').val((new Date()).pattern("yyyy-MM-dd"));
  
  var $alert = $('#my-alert');
  $('#my-start').datepicker().on('changeDate.datepicker.amui', function(event) {
	  if (event.date.valueOf() > endDate.valueOf()) {
		$alert.find('p').text('开始日期应小于结束日期！').end().show();
	  } else {
		$alert.hide();
		startDate = new Date(event.date);
		$('#my-startDate').val($('#my-start').data('date'));
	  }
	  $(this).datepicker('close');
	});

  $('#my-end').datepicker().on('changeDate.datepicker.amui', function(event) {
	  if (event.date.valueOf() < startDate.valueOf()) {
		$alert.find('p').text('结束日期应大于开始日期！').end().show();
	  } else {
		$alert.hide();
		endDate = new Date(event.date);
		$('#my-endDate').val($('#my-end').data('date'));
	  }
	  $(this).datepicker('close');
	});
}


var time="";
time+='<div class="timetcc">';
time+='	<div class="am-alert am-alert-danger" id="my-alert" style="display: none;padding: .225em;position:absolute;bottom:-10px;">';
time+='	  <p>开始日期应小于结束日期！</p>';
time+='	</div>';
time+='	<div>';
time+='		开始时间：';
time+='		<div class="ksjstime">';
time+='			<input type="text" placeholder="" readonly=readonly id="my-startDate"> ';
time+='			<span class="am-icon-calendar" id="my-start"></span>';
time+='		</div>';
time+='		<input type="number" class="textnum" onKeyUp="hour(this);" id="starthour"> : ';
time+='		<input type="number" class="textnum" onKeyUp="second(this);" id="startsecond">';
time+='	</div>';
time+='	<div>';
time+='		结束时间：';
time+='		<div class="ksjstime">';
time+='			<input type="text" placeholder="" readonly=readonly id="my-endDate"> ';
time+='			<span class="am-icon-calendar" id="my-end"></span>';
time+='		</div>';
time+='		<input type="number" class="textnum" onKeyUp="hour(this);" id="endhour"> : ';
time+='		<input type="number" class="textnum" onKeyUp="second(this);" id="endsecond">';
time+='	</div>';
time+='	<div class="am-text-right">';
time+='		<button class="am-btn am-btn-sm am-btn-primary am-radius" type="button" style="padding:5px 8px;" onClick="timehide()">确定</button>';
time+='		<button class="am-btn am-btn-sm am-btn-primary am-radius" type="button" style="padding:5px 8px;" onClick="timeclose()">取消</button>';
time+='	</div>';
time+='</div>';

//时间控件div弹出、隐藏
function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}

function timeshow(){
	timeclose();
	$(".timediv").append(time);
	$("#my-startDate").val($("#starttime").val().substring(0,10));
	$("#starthour").val($("#starttime").val().substring(11,13));
	$("#startsecond").val($("#starttime").val().substring(14,16));
	
	$("#my-endDate").val($("#endtime").val().substring(0,10));
	$("#endhour").val($("#endtime").val().substring(11,13));
	$("#endsecond").val($("#endtime").val().substring(14,16));
	timetime();
}
function timehide(){
	var startdate=$("#my-startDate").val();
	var starthour=$("#starthour").val();
	starthour=checkTime(starthour);
	var startsecond=$("#startsecond").val();
	startsecond=checkTime(startsecond);
	$("#starttime").val(startdate+" "+starthour+":"+startsecond);
	
	var enddate=$("#my-endDate").val();
	var endhour=$("#endhour").val();
	endhour=checkTime(endhour);
	var endsecond=$("#endsecond").val();
	endsecond=checkTime(endsecond);
	$("#endtime").val(enddate+" "+endhour+":"+endsecond);
	
	$(".timetcc").remove();
}
function timeclose(){
	$(".timetcc").remove();
}

//时、分的监控
function hour(obj){
	var hour=$(obj).val();
	if(hour > 24){
		$(obj).val(24);
	}else if(hour <=  0){
		$(obj).val(0);
	}
}
function second(obj){
	var second=$(obj).val();
	if(second > 60){
		$(obj).val(60);
	}else if(second <= 0){
		$(obj).val(0);
	}
}




//ui 时间控件判断js 没有时分的
function timetime1(){
  var startDate = new Date();
  var endDate = new Date();
  var $alert = $('#my-alert1');
  $('#my-start1').datepicker().on('changeDate.datepicker.amui', function(event) {
	  if (event.date.valueOf() > endDate.valueOf()) {
		$alert.find('p').text('开始日期应小于结束日期！').end().show();
	  } else {
		$alert.hide();
		startDate = new Date(event.date);
		$('#my-startDate1').val($('#my-start1').data('date'));
	  }
	  $(this).datepicker('close');
	});

  $('#my-end1').datepicker().on('changeDate.datepicker.amui', function(event) {
	  if (event.date.valueOf() < startDate.valueOf()) {
		$alert.find('p').text('结束日期应大于开始日期！').end().show();
	  } else {
		$alert.hide();
		endDate = new Date(event.date);
		$('#my-endDate1').val($('#my-end1').data('date'));
	  }
	  $(this).datepicker('close');
	});
}

var time1="";
time1+='<div class="timetcc1">';
time1+='	<div class="am-alert am-alert-danger" id="my-alert1" style="display: none;padding: .225em;position:absolute;bottom:-10px;">';
time1+='	  <p>开始日期应小于结束日期！</p>';
time1+='	</div>';
time1+='	<div>';
time1+='		开始时间：';
time1+='		<div class="ksjstime">';
time1+='			<input type="text" placeholder="" readonly=readonly id="my-startDate1"> ';
time1+='			<span class="am-icon-calendar" id="my-start1"></span>';
time1+='		</div>';
time1+='	</div>';
time1+='	<div>';
time1+='		结束时间：';
time1+='		<div class="ksjstime">';
time1+='			<input type="text" placeholder="" readonly=readonly id="my-endDate1"> ';
time1+='			<span class="am-icon-calendar" id="my-end1"></span>';
time1+='		</div>';
time1+='	</div>';
time1+='	<div class="am-text-right">';
time1+='		<button class="am-btn am-btn-sm am-btn-primary am-radius" type="button" style="padding:5px 8px;" onClick="timehide1()">确定</button>';
time1+='		 <button class="am-btn am-btn-sm am-btn-primary am-radius" type="button" style="padding:5px 8px;" onClick="timeclose1()">取消</button>';
time1+='	</div>';
time1+='</div>';

//时间控件div弹出、隐藏
function timeshow1(){
	timeclose1();
	$(".timediv1").append(time1);
	$("#my-startDate1").val($("#starttime1").val());
	$("#my-endDate1").val($("#endtime1").val());
	timetime1();
}
function timehide1(){
	var startdate1=$("#my-startDate1").val();
	$("#starttime1").attr("value",startdate1);
	
	var enddate1=$("#my-endDate1").val();
	$("#endtime1").val(enddate1);
	
	$(".timetcc1").remove();
}

function timeclose1(){
	$(".timetcc1").remove();
}

